﻿using System.Windows;
using System.Windows.Input;
using MyWpfApp.Controls;
using ViewModel.Finance;

namespace MyWpfApp.Finance
{
    /// <summary>
    /// Interaction logic for FrequencyItemPropertiesView.xaml
    /// </summary>
    public partial class FrequencyItemPropertiesView : BasePropertyWindow
    {
        private FrequencyPropertiesViewModel viewModel;

        public FrequencyItemPropertiesView()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            viewModel = DataContext as FrequencyPropertiesViewModel;
        }

        private void OKClicked(object sender, RoutedEventArgs e)
        {
            if (!ValidateControlFields()) return;

            if (!viewModel.Save())
            {
                //something bad happend
                return;
            }
            DialogResult = true;

            Close();
        }


        /// <summary>
        /// TODO: need to implement wpf style control validation
        /// </summary>
        /// <returns></returns>
        private bool ValidateControlFields()
        {
            if (txtName.Text == string.Empty)
            {
                txtName.Focus();
                return false;
            }
            return true;
        }
    }
}